import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/dao/user_info_dao.dart';
import 'package:jicaimao_flutter/views/mine/authentication_state_page.dart';
import 'package:jicaimao_flutter/views/mine/card_bind_page.dart';
import 'package:jicaimao_flutter/views/mine/accout_page.dart';
import 'package:jicaimao_flutter/views/mine/blife_bind_page.dart';
import 'package:jicaimao_flutter/views/mine/bsc_bind_page.dart';
import 'package:jicaimao_flutter/views/mine/ide_page.dart';

class SecurityCentre extends StatefulWidget {
  @override
  _SecurityCentreState createState() => new _SecurityCentreState();
}

class _SecurityCentreState extends State<SecurityCentre> {
   bool visible = false;

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        centerTitle: true,
        backgroundColor: Colors.white,
        iconTheme: IconThemeData(color: Colors.black),
        title: new Text(
          '安全中心',
          style: new TextStyle(color: Colors.black),
        ),
        actions: <Widget>[
          IconButton(
              icon: Image.asset('images/img_contans.png'),
              onPressed: () {
                showAlertDialog(context);
              })
        ],
      ),
      body: new Container(
        child: Column(
          children: <Widget>[
            new Offstage(
              offstage: visible,
              child: new Container(
                  child: new Row(
                    children: <Widget>[

                      Expanded(
                        child: new Text(
                          '为了保证你的理财安全,请先完善理财安全信息',
                          style: new TextStyle(
                              color: Color(0xffffa169), fontSize: 14.0),
                        ),
                        flex: 1,
                      ),
                      new GestureDetector(
                        onTap: _getState,
                        child: Image.asset(
                          'images/icon_error.png',
                          width: 20.0,
                          height: 20.0,
                        ),
                      )
                    ],
                  ),

                color: Color(0xFFFCF8FF),
                padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
                height: 40.0,
              ),
            ),
            new Container(
              height: 51.0,
              padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
              color: Color(0xFFF6F5F5),
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Text('产品安全',
                        style: new TextStyle(
//                        fontWeight: FontWeight.bold,
                            fontSize: 15.0,
                            color: Color(0xFF333333))),
                    flex: 1,
                  ),
                  new Text('')
                ],
              ),
            ),
            commentTitle(context, 1, 1, '身份验证', '未认证'),
            commentTitle(context, 2, 2, 'BSC钱包', '已绑定'),
            commentTitle(context, 3, 2, 'B生活', '去绑定'),
            commentTitle(context, 4, 2, '支付密码', '去修改'),
            commentTitle(context, 5, 2, '银行卡', '未绑定'),
            new Container(
              height: 51.0,
              padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
              margin: EdgeInsets.fromLTRB(0.0, 1.0, 0.0, 0.0),
              color: Color(0xFFF6F5F5),
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Text('账号安全',
                        style: new TextStyle(
//                        fontWeight: FontWeight.bold,
                            fontSize: 15.0,
                            color: Color(0xFF333333))),
                    flex: 1,
                  ),
                  new Text('')
                ],
              ),
            ),
            commentTitle(context, 6, 2, '密码登录', '去修改'),
            new Container(
              height: 51.0,
              padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
              margin: EdgeInsets.fromLTRB(0.0, 1.0, 0.0, 0.0),
              color: Color(0xFFF6F5F5),
              child: new Row(
                children: <Widget>[
                  Expanded(
                    child: new Text('安全保护',
                        style: new TextStyle(
//                        fontWeight: FontWeight.bold,
                            fontSize: 15.0,
                            color: Color(0xFF333333))),
                    flex: 1,
                  ),
                  new Text('')
                ],
              ),
            ),
            commentTitle(context, 7, 2, '账号急救', '账号申诉、注销等'),
          ],
        ),
      ),
    );
  }

  _getState() {
    setState(() {
      visible = true;
    });
  }

  void showAlertDialog(BuildContext context) {
    showDialog(
        context: context,
        builder: (_) => new AlertDialog(
                title: new Text("提示"),
                content: new Text("客服功能不支持,你去咬耿宴吧"),
                actions: <Widget>[
                  new FlatButton(
                    child: new Text("咬死他"),
                    onPressed: () {
                      Navigator.of(context).pop();
                    },
                  )
                ]));
  }

  Widget commentTitle(BuildContext context, int type, int state, String title,
      String rightDes) {
    return new GestureDetector(
        child: Container(
          height: 51.0,
          padding: EdgeInsets.fromLTRB(15.0, 0.0, 15.0, 0.0),
          margin: EdgeInsets.fromLTRB(0.0, 1.0, 0.0, 0.0),
          color: Colors.white,
          child: Row(
            children: <Widget>[
              Expanded(
                child: new Text(title),
                flex: 1,
              ),
              new Text(
                rightDes,
                style: TextStyle(color: Color(0xFF999999), fontSize: 13.0),
              ),
              new Icon(
                Icons.keyboard_arrow_right,
                color: Color(0xFF999999),
              )
            ],
          ),
        ),
        onTap: () {
          switch (type) {
            case 1:
              UserInfoDao.getUserSecurityStatus().then((res) {
                if (res != null && res.result) {
                  if (res.data == 0 || res.data == 2) {
                    Future.delayed(const Duration(seconds: 1), () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => AuthenticationIngSatePage()),
                      );
                    });
                  } else {
                    Navigator.push(context,
                        MaterialPageRoute(builder: (context) => IdePage()));
                  }
                }
              });
              break;

            case 2:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => BscBindPage()));
              break;
            case 3:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => BlifeBindPage()));
              break;
            case 4:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => CardBindPage()));
              break;
            case 5:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => CardBindPage()));
              break;
            case 6:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => AccoutPage()));
              break;
            case 7:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => AccoutPage()));
              break;
            default:
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => AccoutPage()));
              break;
          }
        });
  }
}
